using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace InputLib
{

    public enum InputSignal
    {
        LeftThumbstickUp,
        LeftThumbstickDown,
        LeftThumbstickLeft,
        LeftThumbstickRight,
        RightThumbstickUp,
        RightThumbstickDown,
        RightThumbstickLeft,
        RightThumbstickRight,
        ThumbpadUp,
        ThumbpadDown,
        ThumbpadLeft,
        ThumbpadRight,
        X,
        Y,
        A,
        B,
        LB,
        RB,
        LT,
        RT,
        Start,
        Back

    }

    public class InputHandler
    {
        //exposed events to handle input
        public event PlayerOneHandler PlayerOneEvent;
        public delegate void PlayerOneHandler(InputHandler sender, InputEventArgs args);


        public void Update()
        {
            InputEventArgs args1 = null;

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.LeftThumbstickLeft);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.LeftThumbstickRight);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.LeftThumbstickUp);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.LeftThumbstickDown);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.RightThumbstickLeft);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.RightThumbstickRight);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.RightThumbstickDown);
            }
            else if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.RightThumbstickUp);
            }
            else if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.Start);
            }
            else if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                args1 = new InputEventArgs(PlayerIndex.One, InputSignal.Back);
            }

            if (null != args1)
            {
                PlayerOneEvent(this, args1);
            }

        }




    }
}
